<?php
/**
 * Created by JetBrains PhpStorm.
 * User: zhouyang
 * Date: 13-9-7
 * Time: 下午18:31
 * To change this template use File | Settings | File Templates.
 */
class CommentsDB  extends DBReader{

    //获取trend 列表<带分页>
    public function getCommentListByWhoopsFeedID($curr_page,$per_page,$filter = array()){
        $where = ' 1=1 ';
        $bindarr = array();

        if(isset($filter['whoopsfeed_id'])){
            $where .= ' and whoopsfeed_id = :whoopsfeed_id';
            $bindarr['whoopsfeed_id'] = $filter['whoopsfeed_id'];
        }

        if(isset($filter['comment_type'])){
            $where .= ' and comment_type = :comment_type';
            $bindarr['comment_type'] = $filter['comment_type'];
        }

        $where .= ' and status >= :status';
        $bindarr['status'] = 3;

        $ret = $this->pager($curr_page, $per_page)
            ->ct('select count(comment_id) from comments where ' . $where , $bindarr)
            ->rs('select comment_id, comment_pid, comment_text, user_id, nick_name, face, add_time from comments where '.$where.' order by add_time desc',$bindarr);

        return $ret;
    }

    //获取首页推荐的最新3条数据
    public function getRecommendIndexList(){

        $sql = 'select comment_id, comment_pid, comment_text, user_id, nick_name, face, add_time from comments where status = 5 order by add_time desc';

        return $this->db()->selectLimit($sql,10);
    }

    public function getTopByCommentType($comment_type,$limit = 6){
        $sql = 'select whoopsfeed_id from comments where comment_type = :comment_type and status >= :status group by whoopsfeed_id limit 0,'.$limit;

        return $this->db()->getOneAll($sql, array('comment_type'=>$comment_type,'status'=>3));
    }
}